<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="\static\js\jquery-3.7.1.min.js"></script>
    <style>
        h1{
            text-align: center;
        }
        table {
                margin-top: 40px;
                width: 100%;
                border-collapse: collapse;
                border: 2px solid #333;
            }
    
            th,
            td {
                padding: 10px;
                text-align: center;
                border-bottom: 1px solid #ddd;
            }
    
            th {
                background-color: #f2f2f2;
                color: #333;
            }
    
            tr:nth-child(even) {
                background-color: #f9f9f9;
            }
    
            tr:nth-child(odd) {
                background-color: #a2cb89;
            }
    
            tbody tr:nth-child(odd) {
                background-color: #d9d9d9;
            }
    
            table thead tr td {
                font: 1.5em sans-serif;
            }
    
            table caption {
                font: 2em sans-serif;
            }
    </style>
</head>

<body>
    <h1>爬虫信息</h1>

    <table>
        <thead>
        <tr>
            <td>时间</td>
            <td>标题</td>
            <td>链接</td>
        </tr>
        </thead>
        <tbody id="results">
        </tbody>
    </table>
    <script>
        $.get("/proxy?url=https://hceb.edu.cn/xwzx/mtjm.htm", function (data) {

            // data 中包含网页的 HTML 代码
            let news = [];
            $.each($(data).find("div.m_new1 li"), function (index, element) {
                news.push({
                    time: $(element).find("cite").text(),
                    title: $(element).find("span").text(),
                    link: $(element).find("span a").attr("href")
                });
            });

            // 按照时间顺序对新闻进行排序
            news.sort(function(a, b) {
                return new Date(b.time) - new Date(a.time);
            });

            // 将排序后的新闻添加到表格中
            $.each(news, function (index, item) {
                $("#results").append("<tr><td>" + item.time + "</td><td>" + item.title + "</td><td><a href='" + item.link + "'>链接</a></td></tr>");
            });

            let totol = $(data).find("span.p_t").text();
            let totalNum = parseInt(totol.match(/\d+/)[0]);
            let totalPage = Math.ceil(totalNum / 20);
            for (let i = totalPage - 1; i > 0; i--) {
                let url = 'https://hceb.edu.cn/xwzx/mtjm/' + i + '.htm';
                $.get("/proxy?url=" + url, function (data) {
                    $.each($(data).find("div.m_new1 li"), function (index, element) {
                        news.push({
                            time: $(element).find("cite").text(),
                            title: $(element).find("span").text(),
                            link: $(element).find("span a").attr("href")
                        });
                    });

                    // 按照时间顺序对新闻进行排序
                    news.sort(function(a, b) {
                        return new Date(b.time) - new Date(a.time);
                    });

                    // 将排序后的新闻添加到表格中
                    $.each(news, function (index, item) {
                        $("#results").append("<tr><td>" + item.time + "</td><td>" + item.title + "</td><td><a href='" + item.link + "'>链接</a></td></tr>");
                    });
                });
            }
        });

    </script>
</body>
</html>

<!-- <!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="\static\js\jquery-3.7.1.min.js"></script>
    <style>
        h1{
            text-align: center;
        }
        table {
                margin-top: 40px;
                width: 100%;
                border-collapse: collapse;
                border: 2px solid #333;
            }
    
            th,
            td {
                padding: 10px;
                text-align: center;
                border-bottom: 1px solid #ddd;
            }
    
            th {
                background-color: #f2f2f2;
                color: #333;
            }
    
            tr:nth-child(even) {
                background-color: #f9f9f9;
            }
    
            tr:nth-child(odd) {
                background-color: #a2cb89;
            }
    
            tbody tr:nth-child(odd) {
                background-color: #d9d9d9;
            }
    
            table thead tr td {
                font: 1.5em sans-serif;
            }
    
            table caption {
                font: 2em sans-serif;
            }
    </style>
</head>

<body>
    <h1>爬虫信息</h1>

    <table>
        <thead>
        <tr>
            <td>时间</td>
            <td>标题</td>
            <td>链接</td>
        </tr>
        </thead>
        <tbody id="results">
        </tbody>
    </table>
    <script>
        $.get("/proxy?url=https://hceb.edu.cn/xwzx/mtjm.htm", function (data) {

            // data 中包含网页的 HTML 代码
            $.each($(data).find("div.m_new1 li"), function (index, element) {
                console.log(index, $(element).find("cite").text(), $(element).find("span").text(), $(element).find("span a").attr("href"));
            });

            let totol = $(data).find("span.p_t").text();
            let totalNum = parseInt(totol.match(/\d+/)[0]);
            let totalPage = Math.ceil(totalNum / 20);
            for (let i = totalPage - 1; i > 0; i--) {
                let url = 'https://hceb.edu.cn/xwzx/mtjm/' + i + '.htm';
                $.get("/proxy?url=" + url, function (data) {
                    $.each($(data).find("div.m_new1 li"), function (index, element) {
                        console.log(index, $(element).find("cite").text(), $(element).find("span").text(), $(element).find("span a").attr("href"));
                    });
                });
            }
        });

    </script>
</body>
 -->
